import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;

public class justATest5 {
	// Declare the objects and variables to use
	FirefoxDriver driver;
	String baseUrl;
	
	@Before
	public void setUp() throws Exception {
		driver = new FirefoxDriver(); // creating an object instance
		baseUrl = "http://www.youtube.com/";
	}
	
	@Test
	public void test1() throws Exception {
		String iSearchTerm, oSearchResults, eSearchResults;
		String iWText, oWText;
		int iWait, i;
		String i1, i2, i3, i4;
		
		i1 = "";
		i2 = "Automation";
		i3 = "Training";
		i4 = "Videos";
		iWText = "Sign in to add channels to your homepage"; 
		
		iWait = 2000;
		iSearchTerm = "Selenium";
		eSearchResults = "About 13,300 results";
		
		for (i=1; i<4; i++) {
			//TC001 - Search Results (Basic Test)
			if (i==1){
				iSearchTerm = "Selenium" + i1;
			}
			if (i==2){
				iSearchTerm = "Selenium " + i2;
			}
			if (i==3){
				iSearchTerm = "Selenium " + i3;
			}
			if (i==4){
				iSearchTerm = "Selenium " + i3;
			}
			
			driver.get(baseUrl); 
			Thread.sleep(iWait);
			//TC005 - Welcome text on home page
			//1. Get the text from the location
			oWText = driver.findElement(By.xpath("//html/body/div[2]/div[2]/div/div[3]/div/div/h2")).getText();
			//2. Compare the text 			//3. Print Pass or fail 
			if (iWText.equals(oWText)){
				System.out.println("TC005 is a pass ");
			} else {
				System.out.println("TC005 is a fail ");
			}
			
			// TC001
			driver.findElement(By.xpath("//input[@id='masthead-search-term']")).sendKeys(iSearchTerm);
			driver.findElement(By.xpath("//button[@id='search-btn']")).click();
			Thread.sleep(iWait);
			oSearchResults = driver.findElement(By.xpath("//p[@class='num-results']")).getText();
			System.out.println("The search numbers are : " + oSearchResults);
			if (eSearchResults.equals(oSearchResults)){
				System.out.println("TC001 Pass " + i);
			} else {
				System.out.println("TC001 Fail " + i);
			}
		}
				
	}
	
	@After
	public void tearDown() throws Exception {
		driver.quit();
	}

}
